.model small,c    
.586
.data

PCI_ADDR   equ    0cf8h
PCI_DATA   equ    0cfch
ENABLE_BIT equ    80000000h
.code

;
;C Prototype
;DWORD Read_PCI_DWord (BYTE bus,BYTE dev,BYTE func,BYTE reg)
;{
;}
;
public Read_PCI_DWord
Read_PCI_DWord proc near ,\
			 bus:byte,\
			 dev:byte,\
			 func:byte,\
			 reg:byte
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    in    eax, dx

    mov   edx, eax
    shr   edx, 16   

    ret
Read_PCI_DWord endp

;
;C Prototype
;WORD Read_PCI_Word(BYTE bus,BYTE dev,BYTE func,BYTE reg)
;{
;}
;
public Read_PCI_Word
Read_PCI_Word proc near  ,\
			bus:byte,\
			dev:byte,\
			func:byte,\
			reg:byte
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    mov   al,  reg
    and   al,  2
    add   dl,  al
    in    ax,  dx

    ret
Read_PCI_Word endp

;
;C Prototype
;BYTE Read_PCI_Byte (BYTE bus,BYTE dev,BYTE func,BYTE reg)
;{
;}
;

public Read_PCI_Byte
Read_PCI_Byte proc near ,
			bus:byte,\
			dev:byte,\
			func:byte,\
			reg:byte
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    mov   al,  reg
    and   al,  3
    add   dl,  al
    in    al,  dx

    ret
Read_PCI_Byte endp
;
;

public Write_PCI_Dword
Write_PCI_Dword proc near uses eax dx,\
			bus:byte,\
			dev:byte,\
			func:byte,\
			reg:byte,\
			val:dword   
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    mov   eax, val
    out   dx,  eax 

    ret
Write_PCI_Dword endp




;
;C Prototype
;void Write_PCI_Word( BYTE bus,BYTE dev,BYTE func,BYTE reg,WORD value)
;
;

public Write_PCI_Word
Write_PCI_Word proc near uses eax dx,\
			bus:byte,\
			dev:byte,\
			func:byte,\
			reg:byte,\
			val:word
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    mov   al,  reg
    and   al,  02h
    add   dl,  al
    mov   ax,  val
    out   dx,  ax 

    ret

Write_PCI_Word endp

;
;C Prototype
;void Write_PCI_Byte(BYTE bus,BYTE dev,BYTE func,BYTE reg,BYTE value)
;
;

public Write_PCI_Byte
Write_PCI_Byte proc near uses eax dx,\
			bus:byte,\
			dev:byte,\
			func:byte,\
			reg:byte,\
			val:byte
    xor   eax, eax
    mov   al , bus
    shl   eax, 5
    add   al , dev
    shl   eax, 3
    add   al , func
    shl   eax, 8
    mov   al , reg
    and   al , 0fch
    or    eax, ENABLE_BIT

    mov   dx,  PCI_ADDR
    out   dx,  eax

    jmp   $+2
    mov   dx,  PCI_DATA
    mov   al,  reg
    and   al,  03h
    add   dl,  al
    mov   al,  val
    out   dx,  al 

    ret

Write_PCI_Byte endp

end
